package com.sduept.nwld.dataserver.manager.protection;

import com.sduept.core.dao.SuperDAO;
import com.sduept.nwld.dataserver.model.daily.BreakerStartRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class NewDeviceManager {
	@Autowired
	SuperDAO dao;

	public List<BreakerStartRecord> getBreakerStartRecord() {
//		Date s = DateUtil.getDateByString(start, DateUtil.pattern_ymdhms);
//		Date e = DateUtil.getDateByString(end, DateUtil.pattern_ymdhms);
//		return dao.findByCondition(BreakerStartRecord.class,
//				" workTime between ? and ? ", s, e);
		return  dao.findAll(BreakerStartRecord.class, "order by id");		
	}
	public List<BreakerStartRecord> getBreakerStartRecord(Date start,Date end) {
		String where = " recordingTime between ? and ? ";
		List<BreakerStartRecord> obs = dao.findByCondition(BreakerStartRecord.class, where, start,end);
		return obs;
	}
	
	
	/**
	 * 数据更新
	 */
	public void updateBreakerStartRecord(BreakerStartRecord selected) {
		if (selected != null) {
			try {
				dao.update(selected, BreakerStartRecord.class); 
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * 新增数据
	 * 
	 * @return
	 */
	public BreakerStartRecord creatBreakerStartRecord(BreakerStartRecord created) {
		if (created != null) {
			try {
				created = dao.update(created, BreakerStartRecord.class);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return created;
	}

	/**
	 * 单条删除
	 */
	public void delBreakerStartRecord(BreakerStartRecord selectDevices) {
		if (selectDevices != null) {
			try {
				dao.delete(selectDevices.getId(), BreakerStartRecord.class);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
